﻿<Window x:Class="Brjnk.GpxExplorer.UI.BitmapExportEditorWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:be="clr-namespace:Brjnk.GpxExplorer.Workspace.BitmapExport"
        xmlns:bitmapExport="clr-namespace:Brjnk.GpxExplorer.Workspace.BitmapExport"
        xmlns:common="clr-namespace:Brjnk.Common;assembly=Common"
        xmlns:l="clr-namespace:Brjnk.GpxExplorer.Localization"
        xmlns:my="clr-namespace:Brjnk.GpxExplorer.UI.Controls"
        Title="{l:Loc titleBitmapExport}"
        Width="800"
        Height="600"
        MinWidth="500"
        MinHeight="330"
        FocusManager.FocusedElement="{Binding ElementName=okButton}"
        WindowStartupLocation="CenterOwner">
    <Grid>
        <Grid.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="pack://application:,,,/GpxExplorer;component/Resources/BitmapExport.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="2*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TabControl Name="tabs" SelectionChanged="tabs_SelectionChanged">
            <TabItem Header="{l:Loc bitmapExportWaypoints}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <ListView Name="lvWaypointLabels"
                              Grid.ColumnSpan="2"
                              ItemsSource="{Binding WaypointLabels}"
                              ItemTemplate="{StaticResource LabelItemTemplate}" />

                    <TextBlock Grid.Row="1" Text="{l:Loc bitmapExportGroupMode}" />
                    <my:EnumPicker Grid.Row="1"
                                   Grid.Column="1"
                                   EnumType="{x:Type be:LabelsGroupMode}"
                                   Value="{Binding WaypointsGroup.Mode}" />
                </Grid>
            </TabItem>
            <TabItem Header="{l:Loc bitmapExportRoutes}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <ListView Name="lvRouteLabels"
                              Grid.ColumnSpan="2"
                              ItemsSource="{Binding RouteLabels}"
                              ItemTemplate="{StaticResource LabelItemTemplate}" />

                    <TextBlock Grid.Row="1" Text="{l:Loc bitmapExportGroupMode}" />
                    <my:EnumPicker Grid.Row="1"
                                   Grid.Column="1"
                                   EnumType="{x:Type be:LabelsGroupMode}"
                                   Value="{Binding RoutesGroup.Mode}" />
                </Grid>
            </TabItem>
            <TabItem Header="{l:Loc bitmapExportTracks}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <ListView Name="lvTrackLabels"
                              Grid.ColumnSpan="2"
                              ItemsSource="{Binding TrackLabels}"
                              ItemTemplate="{StaticResource LabelItemTemplate}" />
                    <TextBlock Grid.Row="1" Text="{l:Loc bitmapExportGroupMode}" />
                    <my:EnumPicker Grid.Row="1"
                                   Grid.Column="1"
                                   EnumType="{x:Type be:LabelsGroupMode}"
                                   Value="{Binding TracksGroup.Mode}" />
                </Grid>
            </TabItem>
            <TabItem Header="{l:Loc bitmapExportUserLables}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <ListView Name="lvUserLabels"
                              Grid.ColumnSpan="2"
                              ItemsSource="{Binding UserLabels}"
                              ItemTemplate="{StaticResource UserLabelItemTemplate}" />
                    <Button Grid.Row="1"
                            Command="{Binding DataContext.AddUserLabelCommand,
                                              RelativeSource={RelativeSource Mode=FindAncestor,
                                                                             AncestorType=Window}}"
                            Content="{l:Loc exportBitmapAddLabel}" />
                    <Button Grid.Row="1"
                            Grid.Column="1"
                            Command="{Binding DataContext.RemoveUserLabelCommand,
                                              RelativeSource={RelativeSource Mode=FindAncestor,
                                                                             AncestorType=Window}}"
                            CommandParameter="{Binding ElementName=lvUserLabels,
                                                       Path=SelectedItem}"
                            Content="{l:Loc exportBitmapRemoveLabel}" />
                </Grid>
            </TabItem>
        </TabControl>

        <!--  Náhled  -->
        <Viewbox Grid.RowSpan="2"
                 Grid.Column="1"
                 Stretch="Uniform"
                 StretchDirection="DownOnly">
            <Border BorderBrush="LightBlue" BorderThickness="2">
                <Grid Name="outputSource"
                      Width="{Binding Page.Width}"
                      Height="{Binding Page.Height}"
                      Background="{Binding Background,
                                           Converter={StaticResource ColorToBrushConverter}}"
                      ClipToBounds="True">
                    <Grid.ContextMenu>
                        <ContextMenu>
                            <MenuItem Click="MenuItem_Click" Header="{l:Loc exportBitmapCreateLabel}" />
                        </ContextMenu>
                    </Grid.ContextMenu>
                    <Border>
                        <Border.Background>
                            <VisualBrush Visual="{Binding AreaManager.Area}" />
                        </Border.Background>
                    </Border>

                    <ItemsControl Background="Transparent"
                                  ItemsSource="{Binding Labels}"
                                  MouseMove="MouseMoveHandler">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Canvas />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplateSelector>
                            <common:GenericTemplateSelector>
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:CreatorLabel}" Template="{StaticResource CreatorTemplate}" />
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:Compass}" Template="{StaticResource CompassTemplate}" />
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:UserLabel}" Template="{StaticResource UserLabelTemplate}" />
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:WaypointLabel}" Template="{StaticResource WaypointLabelTemplate}" />
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:RouteLabel}" Template="{StaticResource RouteLabelTemplate}" />
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:TrackLabel}" Template="{StaticResource TrackLabelTemplate}" />
                            </common:GenericTemplateSelector>
                        </ItemsControl.ItemTemplateSelector>
                        <ItemsControl.ItemContainerStyle>
                            <Style TargetType="FrameworkElement">
                                <Setter Property="Canvas.Left" Value="{Binding LeftTopCornerPosition.X}" />
                                <Setter Property="Canvas.Top" Value="{Binding LeftTopCornerPosition.Y}" />
                                <EventSetter Event="MouseDown" Handler="MouseDownHandler" />
                                <EventSetter Event="MouseUp" Handler="MouseUpHandler" />
                            </Style>
                        </ItemsControl.ItemContainerStyle>
                    </ItemsControl>
                </Grid>
            </Border>
        </Viewbox>

        <TabControl Grid.Row="1">
            <TabControl.Style>
                <Style TargetType="TabControl">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding SelectedLabel}" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TabControl.Style>

            <!--  Rozložení labelu  -->
            <TabItem Header="{l:Loc exportBitmapLayout}" IsSelected="true">
                <ScrollViewer>
                    <StackPanel>
                        <CheckBox Name="chbxArrowType"
                                  Content="{l:Loc exportBitmapArrowType}"
                                  IsChecked="{Binding SelectedLabel.ArrowStyle.IsArrowTypeLocal}" />
                        <my:EnumPicker EnumType="{x:Type be:ArrowType}"
                                       IsEnabled="{Binding ElementName=chbxArrowType,
                                                           Path=IsChecked}"
                                       Value="{Binding SelectedLabel.ArrowStyle.ArrowType}" />

                        <CheckBox Name="chbxArrowLength"
                                  Content="{l:Loc exportBitmapArrowLength}"
                                  IsChecked="{Binding SelectedLabel.ArrowStyle.IsArrowLengthLocal}" />
                        <Slider IsEnabled="{Binding ElementName=chbxArrowLength,
                                                    Path=IsChecked}"
                                Maximum="600"
                                Minimum="0"
                                Value="{Binding SelectedLabel.ArrowStyle.ArrowLength}" />

                        <CheckBox Name="chbxArrowThickness"
                                  Content="{l:Loc exportBitmapArrowThickness}"
                                  IsChecked="{Binding SelectedLabel.ArrowStyle.IsArrowThicknessLocal}" />
                        <Slider IsEnabled="{Binding ElementName=chbxArrowThickness,
                                                    Path=IsChecked}"
                                Maximum="50"
                                Minimum="0"
                                Value="{Binding SelectedLabel.ArrowStyle.ArrowThickness}" />

                        <CheckBox Name="chbxRotation"
                                  Content="{l:Loc exportBitmapRotation}"
                                  IsChecked="{Binding SelectedLabel.Style.IsContentRotationLocal}" />
                        <Slider IsEnabled="{Binding ElementName=chbxRotation,
                                                    Path=IsChecked}"
                                IsSnapToTickEnabled="True"
                                Maximum="360"
                                Minimum="0"
                                TickFrequency="10"
                                Value="{Binding SelectedLabel.Style.ContentRotation}" />
                        <UniformGrid Columns="2">
                            <Button Command="{Binding MoveToForegroundCommand}"
                                    CommandParameter="{Binding SelectedLabel}"
                                    Content="{l:Loc exportBitmapToForeground}" />
                            <Button Command="{Binding MoveToBackgroundCommand}"
                                    CommandParameter="{Binding SelectedLabel}"
                                    Content="{l:Loc exportBitmapToBackground}" />
                        </UniformGrid>
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
            <!--  Vzhled  -->
            <TabItem Header="{l:Loc exportBitmapAppereance}">
                <ScrollViewer>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <CheckBox Name="chbxBackground"
                                  Grid.Row="0"
                                  Content="{l:Loc exportBitmapLabelBackground}"
                                  IsChecked="{Binding SelectedLabel.Style.IsBackgroundLocal}" />
                        <CheckBox Name="chbxBackgroundOpacity"
                                  Grid.Row="1"
                                  Content="{l:Loc exportBitmapLabelBackgroundOpacity}"
                                  IsChecked="{Binding SelectedLabel.Style.IsBackgroundOpacityLocal}" />
                        <CheckBox Name="chbxBorder"
                                  Grid.Row="2"
                                  Content="{l:Loc exportBitmapLabelBorder}"
                                  IsChecked="{Binding SelectedLabel.Style.IsBorderLocal}" />
                        <CheckBox Name="chbxBorderOpacity"
                                  Grid.Row="3"
                                  Content="{l:Loc exportBitmapLabelBorderOpacity}"
                                  IsChecked="{Binding SelectedLabel.Style.IsBorderOpacityLocal}" />
                        <CheckBox Name="chbxBorderThickness"
                                  Grid.Row="4"
                                  Content="{l:Loc exportBitmapLabelBorderThickness}"
                                  IsChecked="{Binding SelectedLabel.Style.IsBorderThicknessLocal}" />
                        <CheckBox Name="chbxFontColor"
                                  Grid.Row="5"
                                  Content="{l:Loc bitmapExportFontColor}"
                                  IsChecked="{Binding SelectedLabel.Style.IsFontColorLocal}" />
                        <CheckBox Name="chbxFontSize"
                                  Grid.Row="6"
                                  Content="{l:Loc bitmapExportFontSize}"
                                  IsChecked="{Binding SelectedLabel.Style.IsFontSizeLocal}" />
                        <Slider Grid.Row="6"
                                Grid.Column="1"
                                IsEnabled="{Binding Path=IsChecked,
                                                    ElementName=chbxFontSize}"
                                Maximum="60"
                                Minimum="1"
                                Value="{Binding SelectedLabel.Style.FontSize}" />

                        <my:ColorPicker Grid.Row="0"
                                        Grid.Column="1"
                                        IsEnabled="{Binding ElementName=chbxBackground,
                                                            Path=IsChecked}"
                                        Color="{Binding SelectedLabel.Style.Background}" />
                        <Slider Grid.Row="1"
                                Grid.Column="1"
                                IsEnabled="{Binding ElementName=chbxBackgroundOpacity,
                                                    Path=IsChecked}"
                                Maximum="1"
                                Minimum="0"
                                Value="{Binding SelectedLabel.Style.BackgroundOpacity}" />
                        <my:ColorPicker Grid.Row="2"
                                        Grid.Column="1"
                                        IsEnabled="{Binding ElementName=chbxBorder,
                                                            Path=IsChecked}"
                                        Color="{Binding SelectedLabel.Style.Border}" />
                        <Slider Grid.Row="3"
                                Grid.Column="1"
                                IsEnabled="{Binding ElementName=chbxBorderOpacity,
                                                    Path=IsChecked}"
                                Maximum="1"
                                Minimum="0"
                                Value="{Binding SelectedLabel.Style.BorderOpacity}" />
                        <Slider Grid.Row="4"
                                Grid.Column="1"
                                IsEnabled="{Binding ElementName=chbxBorderThickness,
                                                    Path=IsChecked}"
                                Maximum="8"
                                Minimum="0"
                                Value="{Binding SelectedLabel.Style.BorderThickness}" />
                        <my:ColorPicker Grid.Row="5"
                                        Grid.Column="1"
                                        IsEnabled="{Binding ElementName=chbxFontColor,
                                                            Path=IsChecked}"
                                        Color="{Binding SelectedLabel.Style.FontColor}" />
                    </Grid>
                </ScrollViewer>
            </TabItem>

            <TabItem Header="{l:Loc exportBitmapContent}">
                <ScrollViewer>
                    <ContentControl Content="{Binding SelectedLabel}">
                        <ContentControl.ContentTemplateSelector>
                            <common:GenericTemplateSelector>
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:WaypointLabel}" Template="{StaticResource WaypointLabelEditTemplate}" />
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:RouteLabel}" Template="{StaticResource RouteLabelEditTemplate}" />
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:TrackLabel}" Template="{StaticResource TrackLabelEditTemplate}" />
                                <common:TemplateDefinition ObjectType="{x:Type bitmapExport:UserLabel}" Template="{StaticResource UserLabelEditTemplate}" />
                            </common:GenericTemplateSelector>
                        </ContentControl.ContentTemplateSelector>
                    </ContentControl>
                </ScrollViewer>
            </TabItem>
        </TabControl>

        <!--  Dolní řádek  -->
        <Grid Name="foot"
              Grid.Row="2"
              Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Button Grid.RowSpan="2"
                    Grid.Column="0"
                    Click="Button_Click"
                    Content="{l:Loc bitmapExportOptions}" />
            <TextBlock Grid.Row="0"
                       Grid.Column="1"
                       Text="{l:Loc Key=bitmapExportDpiX,
                                    Binding={Binding DpiX}}" />
            <TextBlock Grid.Row="1"
                       Grid.Column="1"
                       Text="{l:Loc Key=bitmapExportDpiY,
                                    Binding={Binding DpiY}}" />
            <TextBlock Grid.Row="0"
                       Grid.Column="2"
                       Text="{l:Loc Key=bitmapExportWidth,
                                    Binding={Binding ActualWidth,
                                                     ElementName=outputSource,
                                                     Converter={StaticResource DipToLengthConverter}}}" />
            <TextBlock Grid.Row="1"
                       Grid.Column="2"
                       Text="{l:Loc Key=bitmapExportHeight,
                                    Binding={Binding ActualHeight,
                                                     ElementName=outputSource,
                                                     Converter={StaticResource DipToLengthConverter}}}" />
            <Button Grid.RowSpan="2"
                    Grid.Column="4"
                    Click="Button_Click_3"
                    Content="{l:Loc bitmapExportPreview}" />
            <Button Grid.RowSpan="2"
                    Grid.Column="5"
                    Click="Button_Click_1"
                    Content="{l:Loc cancel}"
                    IsCancel="True" />
            <Button Name="okButton"
                    Grid.RowSpan="2"
                    Grid.Column="6"
                    Click="Button_Click_2"
                    Content="{l:Loc ok}"
                    IsDefault="True" />
        </Grid>
    </Grid>
</Window>